package guiWindows;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.Box;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.plaf.ScrollPaneUI;

import mediator.ConstantsModel;
import mediator.ShowPropertyMediator;

public class GUIShowProperty extends JDialog {

    private static final long serialVersionUID = 1L;
    private JPanel jContentPane;
    private JPanel panelListProperties;
    private JPanel panelButton;
    private JButton closeButton;
	private JButton traceButton;
    private JTextPane resultEditorArea;
    private JScrollPane scrollArea;
    private JPanel resultPanel;
    private Box verticalButtons;
    private JComboBox<String> listModules;

    public GUIShowProperty(){
        super();
        this.initialize();
    }

    private void initialize() {
        this.setSize(ConstantsModel.LTSA_PROPERTY_WIDTH, ConstantsModel.LTSA_PROPERTY_HEIGHT);
        this.setTitle(ConstantsModel.LTSA_PROPERTY_TITLE);
        this.setLocationRelativeTo(null);
        this.setModal(true);
        this.listModules = new JComboBox<String>();
        this.setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getListModules(),BorderLayout.NORTH);
            jContentPane.add(getResultPanel(), BorderLayout.CENTER);
            jContentPane.add(getButtonPanel(), BorderLayout.SOUTH);
            jContentPane.add(getListPropertiesPanel(),BorderLayout.WEST);
        }
        return jContentPane;
    }

    private JPanel getResultPanel(){
        if(resultPanel == null){
            resultPanel = new JPanel();
            resultPanel.setLayout(new BorderLayout());
            resultPanel.add(getScrollArea(),BorderLayout.CENTER);
        }
        return resultPanel;
    }

    public JScrollPane getScrollArea(){
        if(scrollArea == null){
            scrollArea = new JScrollPane();
            scrollArea.setViewportView(getResultEditorArea());
        }
        return scrollArea;
    }

    public JTextPane getResultEditorArea() {
        if(resultEditorArea == null){
            resultEditorArea = new JTextPane();
        }
        return resultEditorArea;
    }

    private Component getButtonPanel() {
        if(panelButton==null){
            panelButton = new JPanel();
            panelButton.setLayout(new FlowLayout());
            panelButton.add(getButtonClose());
            panelButton.add(getButtonTrace());
        }
        return panelButton;
    }

	public JButton getButtonClose(){
        if(closeButton == null){
            closeButton = new JButton();
            closeButton.setText("Close");
        }
        return closeButton;
    }

    public JButton getButtonTrace() {
    	if(traceButton == null){
    		traceButton = new JButton();
    		traceButton.setText("Trace");
        }
        return traceButton;
	}
    
    public JPanel getListPropertiesPanel() {
        if(panelListProperties == null){
            panelListProperties = new JPanel();
            panelListProperties.add(getVerticalsButtons());
        }
        return panelListProperties;
    }

    public Box getVerticalsButtons(){
        if(verticalButtons == null){
            verticalButtons = Box.createVerticalBox();
        }
        return verticalButtons;
    }

    public void addButtonToBox(String str, ActionListener al){
        JButton newButton = new JButton(str);
        newButton.addActionListener(al);
        getVerticalsButtons().add(newButton);
    }

    public void setListenerButtons(ActionListener al){
        this.closeButton.addActionListener(al);
        this.traceButton.addActionListener(al);
    }

    public JComboBox<String> getListModules(){
        return listModules;
    }

    public void setListModules(ArrayList listModuleArray){
        for(int i=0; i<listModuleArray.size();i++){
            listModules.addItem((String)listModuleArray.get(i));
        }
    }
}
